#!/bin/bash
# Test express
# if [] () [[]] (()) let 
# let's begin

# 0 is true or false
# result 0 is true
echo "Testing 0"
if [ 0 ];then
	echo "0 is true"
else	
	echo "0 is false"
fi

echo "Testing 1"
if [ 1 ];then
	echo "1 is true"
else 
	echo "1 is false"
fi

if [ ];then #NULL
	echo "NULL is true"
else
	echo "NULL is false"
fi


if [ xyz ];then #string
	echo "random string is true"
else
	echo "random string is false"
fi

if [ $xyz ];then #undefined var 
	echo "undefined var is true"
else
	echo "undefined var is false"
fi

if [ " "  ];then #blank string
	echo "blank string is true"
else
	echo "blank string is false"
fi


if [ ""  ];then # 0-length string
	echo "0-length string is true"
else
	echo "0-length string is false"
fi

# same 3 
# if test -z "$1"
# if [ -z "$1" ]
# if /usr/bin/test -z "$1"


echo $(( 5>4 ))
echo $(( 4>5 ))
echo $(( 0 ))
echo $(( 1 ))

if (( 4>5 ));then
	echo "4>5"
else
	echo "4>5 false"
fi
if [ 4 -gt 5 ] ; then
	echo "4 -gt 5"
else
	echo "false 4 -gt 5"
fi


# string null or empty
#abc=
if [ ! $fox ];then
	echo "not define"
elif [ -z "$fox" ];then
	echo "0-len string"
else
	echo "string not null or empty"
fi 

files=(/etc/hosts /home/wzq )
for file in ${files[*]}
do
	if [ -e "$file" ];then
		echo "$file exist"
		if [ -f $file ];then
			echo "$file is file"
		elif [ -d $file ];then
			echo "$file is dir"
		else
			echo "not file or dir"
		fi
	else
		echo "$file not exist"
	fi
done


a1=15
b1=20
# error if [ "$a1" -eq 15 &&  "$b1" -eq 20 ];than
# ok  if [ "$a1" -eq 15 -a  "$b1" -eq 20 ];than
if [ "$a1" -eq 15 ] && [ "$b1" -eq 20 ];then
	echo "abc"
fi

